import Mock from 'mockjs'

// 生成随机数据
const generatePurchaseData = () => {
  const data = []
  const statusList = ['待审核', '待入库', '已驳回', '已作废', '已完成']
  const orderTypes = ['普通采购单', '销售集采单']
  const creators = ['张三', '李四', '王五', '赵六']

  for (let i = 1; i <= 20; i++) {
    data.push(
      Mock.mock({
        'orderNo': `PO${new Date().getFullYear()}${Mock.mock('@string("number", 6)')}`,
        'orderType|1': orderTypes,
        'supplier|1': ['京东商城供应商', '天猫优选供应商', '苏宁易购供应商', '小米商城供应商'],
        'warehouse|1': ['北京中心仓', '上海配送中心', '广州物流仓', '深圳分仓'],
        'status|1': statusList,
        'logisticsNo': `LG${Mock.mock('@string("upper", 8)')}`,
        'quantity|50-550': 1,
        'createTime': Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        'creator|1': creators
      })
    )
  }
  return data
}

// 模拟接口
Mock.mock(/\/api\/purchase\/list/, 'get', (options) => {
  const data = generatePurchaseData()
  return {
    code: 200,
    message: 'success',
    data: {
      list: data,
      total: data.length
    }
  }
})

Mock.mock(/\/api\/purchase\/storage/, 'post', (options) => {
  return {
    code: 200,
    message: '入库成功'
  }
})
